package admin

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"web_api_gin/constant"
	. "web_api_gin/controller"
	"web_api_gin/core"
	"web_api_gin/dao"
	"web_api_gin/dto"
)

var SysFileApi = SysFileController{}

type SysFileController struct {
}

// 获取文件列表
func (c *SysFileController) Index(ctx *gin.Context) {
	//搜索条件
	var searchParams *dto.SysFileGetListReq
	if err := ctx.ShouldBind(&searchParams); err != nil {
		ErrorWithMessage(ctx, http.StatusBadRequest, core.ValidatorTranslateError(err))
		return
	}
	//日志列表
	logList, total, err := dao.SysFile.GetList(ctx, searchParams)
	if err != nil {
		ErrorWithMessage(ctx, http.StatusExpectationFailed, err.Error())
		return
	}

	Success(ctx, gin.H{
		"typeList": constant.FileTypeList,
		"list":     logList,
		"total":    total,
		"pageNo":   searchParams.PageNo,
	})
}
